<?php
	// On prolonge la session
	session_start();
	$id_anim='';
	$code='';

	require_once('../../classes/database.php');
	$idconnect=Database::getInstance();

	//vérification des droits de l'utilisateur

		// On teste si la variable de session existe et contient une valeur
		if(empty($_SESSION['id_anim'])){
			// Si inexistante ou nulle, on redirige vers la page de saisie du code
			header('Location: ../recherche.php');
			exit();
		}
		else{
			$id_anim=$_SESSION['id_anim'];
			$code=$_SESSION['code'];
		}
	
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <link rel="stylesheet" href="../../style.css" />
        <?php
			require_once(dirname(__FILE__)."/onglet_animal.php");
			$onglet = affiche_onglets($_SESSION['membre_id']);
		?>
		<!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <!--[if lte IE 7]>
        <link rel="stylesheet" href="../../style_ie.css" />
        <![endif]-->
        <title>Base de données microcèbes</title>

    </head>

    <body>
		<?php include((dirname(dirname(dirname(__FILE__))))."/menu.php"); ?>
		<?php include((dirname(dirname(__FILE__)))."/calcul_age.php"); ?>
		<section id="main">
			<header>
				<h1>Recherche - Pesées animal <?php echo $code;?></h1>
			</header>
			<?php include((dirname(dirname(__FILE__)))."/menu_recherche.php"); ?>
			<section id="animal">
				<?php
					echo $onglet;
				?>

				<section id="contenu">
				<p>
					<?php
						//récupération des pesées
						$query = pg_query($idconnect,"SELECT mesure,resultat_test_simple.description,date_test,experimentateur, resultat_test_simple.unite
						FROM resultat_test_simple,resultat_test,test,type_test
						WHERE id_animal='".$id_anim."'
						AND resultat_test.id_test=test.id_test
						AND resultat_test.id_res=resultat_test_simple.id_res
						AND test.id_type_test=type_test.id_type_test
						AND type_test.label LIKE '%Pesée%' ");

						$int = pg_num_rows($query);
						if($int==0){echo("<p><label>Pas d'informations disponibles</label></p>");}
						else{
							echo "<TABLE BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"3\">";
							echo "<TR ALIGN=\"CENTER\">";
							echo "<TH> Date de pesée </TH>";
							echo "<TH> Expérimentateur </TH>";
							echo "<TH> Age(mois) </TH>";
							echo "<TH> Age(cycle) </TH>";
							echo "<TH> Poids </TH>";
							echo "</TR>";
							while ($back = pg_fetch_assoc($query)) {
								echo "<TR ALIGN=\"CENTER\">";
								if($back["date_test"]){echo "<TD>".date("d/m/Y", strtotime($back["date_test"]))."</TD>";}else{echo "<TD></TD>";}
								if($back["experimentateur"]==0){echo "<TD>".$back["experimentateur"]."</TD>";}else{echo "<TD></TD>";}
								echo "<TD>".calcul_age($_SESSION['date_n'],$back["date_test"])."</TD>";
								echo "<TD>".calcul_age($_SESSION['date_n'],$back["date_test"])/8;
								echo "</TD>";
								if($back["mesure"]){
										echo "<TD>".$back["mesure"]; 
										if ($back["unite"])
											echo $back["unite"];
										echo "</TD>";
								}
								else { 
									echo "<TD></TD>";
								}
							}
							echo "</TABLE><br/>";
							echo "<img src=\"courbe.php?id_anim=$id_anim\"/>";
						}
						?>
				</p>
				</section>
			</section>

		</section>
	</body>
</html>
